// pages/point/point_detail.js
const api = require("../../request/api")
const request = require("../../request/request")
const util = require("../../utils/util")
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title_list: [{name: "收入"},{name: "支出"}],
    chosen_index: 0,
    point_list: [],
    uid: 0,
    page: 1,
    pageSize: 10,
    ctype: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.init_data(options)
    // this.get_point_list()
    this.get_mypointlist()
  },
  init_data() {
    let eshop_id = App.globalData.eshop_id
    this.setData({
      uid: util.getAppValue(App.globalData.uid),
      shop_id: eshop_id,
    })
  },
  get_mypointlist() {
    let params = {
      // uid: this.data.uid
      uid: this.data.uid,
      page: this.data.page,
      pageSize: this.data.pageSize,
      ctype: this.data.ctype
    }
    console.log(params);
    request.post(api.mypointlist, params).then(res=>{
      if (this.data.chosen_index==0) {
        
      }
      this.setData({
        point_list: res,
      })
    })
  },
  changing_tab(e) {
    let chosen_index = e.currentTarget.dataset.index
    let ctype = chosen_index
    this.setData({
      chosen_index,
      pageSize: 10,
      ctype,
    })
    this.get_mypointlist()
  },
  // get_point_list() {
  //   this.setData({
  //     point_list: [{
  //       title: '签到赠送积分5.00',
  //       point: 5,
  //       time: '2022-01-18'
  //     },{
  //       title: '签到赠送积分5.00',
  //       point: 5,
  //       time: '2022-01-18'
  //     },{
  //       title: '签到赠送积分5.00',
  //       point: 5,
  //       time: '2022-01-18'
  //     },
  //   ]
  //   })
  // },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    let pageSize = this.data.pageSize
    pageSize += 10
    this.setData({
      pageSize
    })
    this.get_mypointlist()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})